//
//  XHMakePhoneCallViewController.m
//  elxc-jl
//
//  Created by 冷山 on 16/5/6.
//  Copyright © 2016年 lexingsoft. All rights reserved.
//

#import "XHMakePhoneCallViewController.h"

#define SCREEN_HEIGHT                   ([UIScreen mainScreen].bounds.size.height)
#define SCREEN_WIDTH                    ([UIScreen mainScreen].bounds.size.width)


@interface XHMakePhoneCallViewController ()
@property (weak, nonatomic) IBOutlet UIView *ui_bgView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *la_bgViewHeight;
@property (weak, nonatomic) IBOutlet UILabel *ui_contactPerson;
@property (weak, nonatomic) IBOutlet UILabel *ui_contactNumber;
@property (weak, nonatomic) IBOutlet UILabel *ui_service;
@property (weak, nonatomic) IBOutlet UILabel *ui_content;

@property (strong, nonatomic) NSTimer *timer;
@end

@implementation XHMakePhoneCallViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.ui_bgView.layer.masksToBounds = YES;
    self.ui_bgView.layer.cornerRadius = 5;
    [self service:self.m_service content:self.m_content];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self goAnimation];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)service:(NSString *)service content:(NSString*)content
{
    self.ui_service.text = @"联系我们";
    self.ui_content.text = @"是否拨打电话:400-808-3555";
}

- (void)goAnimation
{
    CGPoint startPoint = CGPointMake((SCREEN_WIDTH-270)/2, -(SCREEN_HEIGHT-138)/2);
    self.ui_bgView.layer.position=startPoint;
    [UIView animateWithDuration:.8 delay:0 usingSpringWithDamping:.5 initialSpringVelocity:1.0 options:UIViewAnimationOptionCurveLinear animations:^{
        CGPoint startPoint = CGPointMake((SCREEN_WIDTH-270)/2, (SCREEN_HEIGHT-138)/2 +138);
        self.ui_bgView.layer.position=startPoint;
        self.la_bgViewHeight.constant = (SCREEN_HEIGHT-138)/2;
        
    } completion:^(BOOL finished) {
        
    }];

}
//打电话
- (IBAction)callUpAction:(id)sender
{
    NSString *phoneNumber=@"400-808-3555";
    NSURL *url=[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",phoneNumber]];
    [[UIApplication sharedApplication] openURL:url];
    [self cancelViewController];
}
//取消
- (IBAction)cancelAction:(id)sender
{
    [UIView animateWithDuration:0.35 animations:^{
        
        self.la_bgViewHeight.constant = -235;
        [self.view layoutIfNeeded];
    }];
    self.timer = [NSTimer scheduledTimerWithTimeInterval:0.35
                                                  target:self selector:@selector(cancelViewController) userInfo:nil repeats:YES];
}

- (void)cancelViewController
{
    [self dismissViewControllerAnimated:NO completion:^{
    }];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
